package com.wanxi.controller;

import com.wanxi.model.ResultModel;
import com.wanxi.model.StoresModel;
import com.wanxi.service.StoresService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 杨金乾
 */
@Controller
@CrossOrigin(origins = "*")
@Api(tags = "门店管理")
public class StoresController  {
    @Autowired
    StoresService storesService;
    @Autowired
    SendMessageController sendMessageController;
    private String table="门店";
    @RequestMapping("/back/stores/add")
    @ResponseBody
    @ApiOperation(value = "新增一条门店数据")
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')")
    protected ResultModel storesAdd(StoresModel storesModel) {
//
        ResultModel resultModel =storesService.add(storesModel);
        sendMessageController.addUserMessages(table);
//        6.返回给前端
        return resultModel;
    }

    @RequestMapping("/back/stores/delete")
    @ResponseBody
    @ApiOperation(value = "删除一条门店数据")
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')")
    protected ResultModel storesDelete(StoresModel storesModel) {
//
        ResultModel resultModel =storesService.delete(storesModel);
        sendMessageController.deleteUserMessages(table);
//        6.返回给前端
        return resultModel;
    }

    @RequestMapping("/back/stores/findAll")
    @ResponseBody
    @ApiOperation(value = "查询全部门店数据")
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')or hasAuthority('unaccessible')")
    protected ResultModel storesFindAll(StoresModel storesModel) {
//
        ResultModel resultModel =storesService.findAll(storesModel);
        sendMessageController.findAllUserMessages(table);
//        6.返回给前端
        return resultModel;
    }

    @RequestMapping("/back/stores/findById")
    @ResponseBody
    @ApiOperation(value = "查询一条门店的全部数据")
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')or hasAuthority('unaccessible')")
    protected ResultModel storesFindById(StoresModel storesModel) {
//
        ResultModel resultModel =storesService.findById(storesModel);
        sendMessageController.findByIdUserMessages(table);
//        6.返回给前端
        return resultModel;
    }

    @RequestMapping("/back/stores/isShow")
    @ResponseBody
    @ApiOperation(value = "是否显示门店数据")
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')or hasAuthority('unaccessible')")
    protected ResultModel storesUpdateIsShow(StoresModel storesModel) {
        ResultModel resultModel =storesService.isShow(storesModel);
        sendMessageController.updateIsShowMessages(table);
//        6.返回给前端
        return resultModel;
    }

    @RequestMapping("/back/stores/update")
    @ResponseBody
    @ApiOperation(value = "修改一条门店数据")
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')")
    protected ResultModel storesUpdate(StoresModel storesModel) {
//
        ResultModel resultModel =storesService.update(storesModel);
        sendMessageController.updateMessages(table);
//        6.返回给前端
        return resultModel;
    }
}
